package cn.iocoder.yudao.module.famous.doctor.controller.app.question;

import cn.iocoder.yudao.module.famous.doctor.controller.admin.diseaseLabel.vo.DiseaseLabelRespVO;
import cn.iocoder.yudao.module.famous.doctor.dal.mysql.diseaseLabel.DiseaseLabelMapper;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.famous.doctor.controller.admin.question.vo.*;
import cn.iocoder.yudao.module.famous.doctor.dal.dataobject.question.FamQuestionDO;
import cn.iocoder.yudao.module.famous.doctor.convert.question.FamQuestionConvert;
import cn.iocoder.yudao.module.famous.doctor.service.question.FamQuestionService;

@Tag(name = "用户 APP - 常见问题")
@RestController
@RequestMapping("/famous.doctor/fam-question/app")
@Validated
public class AppFamQuestionController {

    @Resource
    private FamQuestionService famQuestionService;

    @Resource
    private DiseaseLabelMapper diseaseLabelMapper;

    @GetMapping("/page")
    @Operation(summary = "获得常见问题分页")
    public CommonResult<PageResult<FamQuestionRespVO>> getFamQuestionPage(@Valid FamQuestionPageReqVO pageVO) {
        PageResult<FamQuestionDO> pageResult = famQuestionService.getFamQuestionPage(pageVO);
        PageResult<FamQuestionRespVO> famQuestionRespVOPageResult = FamQuestionConvert.INSTANCE.convertPage(pageResult);
        famQuestionRespVOPageResult.getList().forEach(famQuestionRespVO -> {
            String diseaseLabelIds = famQuestionRespVO.getDiseaseLabelIds();
            List<DiseaseLabelRespVO> diseaseLabelRespVOList=diseaseLabelMapper.selectInids(diseaseLabelIds);
            famQuestionRespVO.setDiseaseLabelRespVOList(diseaseLabelRespVOList);
        });
        return success(famQuestionRespVOPageResult);
    }

    @PutMapping("/update")
    @Operation(summary = "更新常见问题")
    public CommonResult<Boolean> updateFamQuestion(@Valid @RequestBody FamQuestionUpdateReqVO updateReqVO) {
        famQuestionService.updateFamQuestion(updateReqVO);
        return success(true);
    }

}
